﻿package Framework.Protocol.CDFProtocol
{
    import Framework.Protocol.*;
    import Framework.Serialize.*;
    import Framework.Util.*;
    import flash.utils.*;

    public class GroupProtocol extends Object implements IProtocol, IBusinessHandler
    {
        private var _buttonProtocol:IProtocol;

        public function GroupProtocol(param1:IProtocol)
        {
            this._buttonProtocol = param1;
            return;
        }// end function

        public function handleData(param1:ByteArray, param2:IBusinessHandler, param3:IIOHandler, param4:IBusinessHandler) : int
        {
            return this._buttonProtocol.handleData(param1, this, param3, param2);
        }// end function

        public function handlePacket(param1:ByteArray, param2:IBusinessHandler) : Boolean
        {
            var _loc_3:uint = 0;
            var _loc_4:uint = 0;
            var _loc_5:ByteArray = null;
            while (param1.position < param1.length)
            {
                
                _loc_3 = param1.readUnsignedByte();
                if (_loc_3 == 255)
                {
                    _loc_4 = param1.readUnsignedInt();
                }
                else
                {
                    _loc_4 = _loc_3;
                }
                _loc_5 = new ByteArray();
                param1.readBytes(_loc_5, 0, _loc_4);
                param2.handlePacket(_loc_5, null);
            }
            return true;
        }// end function

        public function sendDataEncrypt(param1:ByteArray, param2:IIOHandler) : Boolean
        {
            var _loc_3:* = new SerializeStream();
            _loc_3.writeSize(param1.length);
            _loc_3.byteArray.writeBytes(param1, 0, param1.length);
            _loc_3.byteArray.position = 0;
            return this._buttonProtocol.sendDataEncrypt(_loc_3.byteArray, param2);
        }// end function

        public function clear() : void
        {
            if (this._buttonProtocol)
            {
                this._buttonProtocol.clear();
            }
            return;
        }// end function

        public function get buttonProtocol() : IProtocol
        {
            return this._buttonProtocol;
        }// end function

        public function set buttonProtocol(param1:IProtocol) : void
        {
            this._buttonProtocol = param1;
            return;
        }// end function

    }
}
